/*
 * @Description: 开发环境
 * @Author: wangqi
 * @Date: 2021-03-02 20:47:11
 * @LastEditTime: 2021-03-17 16:56:37
 */
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const common = require('./webpack.common');
const ip = require('ip').address();


console.log(process.env.NODE_ENV, "开发环境");

module.exports = merge(common, {
    // development || production
    mode: "development",
    target: "web",
    devtool: 'eval-source-map',
    devServer: {
        port: 3001,
        host: 'localhost',
        hot: true,
        // 启动gzip压缩
        compress: true,
        // 只有在输出的时候会报错
        // stats: "errors-only",
        // 项目构建后路径
        contentBase: path.resolve(__dirname, './dist'),
        // overlay: {
        //     warnings: true,
        //     errors: true,
        // },
        after() {
            console.log(`成功打开链接： http://${ip}:${this.port}`);
        },
    },
    module: {
        rules: [
            {
                oneOf: [
                    {
                        test: /\.css$/,
                        use: [
                            'style-loader', 'css-loader', 'postcss-loader'
                        ],
                        // 不检测的文件
                        exclude: /node_modules/,
                        // 指定检查的目录
                        include: path.resolve(__dirname, 'src'),
                    },
                    {
                        test: /\.(less)$/i,
                        use: ['style-loader', 'css-loader', 'less-loader', 'postcss-loader'
                            // options: {
                            //     ident: 'postcss',
                            //     plugins: () => [require('postcss-preset-env')()]
                            // }
                        ],
                        // 不检测的文件
                        exclude: /node_modules/,
                        include: path.resolve(__dirname, 'src'),
                    }
                ]
            }

        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
    ],

})
